import { action, makeAutoObservable } from "mobx";
import { stringToBinary } from "@/utils/common";

export default class FountainCodeStore {

    originData: string = '';
    originDataBinary: string = '';

    blockSize: number = 16;

    packageList: any[] = [];

    mockDropRate: number = 10;

    needCount: number = 0;

    receivedPackageList: any[] = [];

    decodeResult: string = '';

    mocking: boolean = false;

    packageSent: number = 0;
    packageSuccess: number = 0;
    packageLost: number = 0;

    constructor() {
            makeAutoObservable(this, {}, { autoBind: true });
    }

    @action
    setOriginData = (_d: string) => {
        this.originData = _d;
        this.originDataBinary = stringToBinary(_d);
    }

    @action
    setBlockSize = (_s: number) => {
        this.blockSize = _s;
    }

    @action
    setPackageList = (_l: any[]) => {
        this.packageList = _l;
    }

    @action
    addPackageList = (_l: any[]) => {
        this.packageList = [...this.packageList, ..._l];
    }

    @action
    setMockDropRate = (_r: number) => {
        this.mockDropRate = _r;
    }

    @action
    setNeedCount = (_c: number) => {
        this.needCount = _c;
    }

    @action
    setReceivedPackageList = (_l: any[]) => {
        this.receivedPackageList = _l;
    }

    @action
    setDecodeResult = (_r: string) => {
        this.decodeResult = _r;
    }

    @action
    setMocking = (_m: boolean) => {
        this.mocking = _m;
    }

    @action
    setPackageSent = (_s: number) => {
        this.packageSent = _s;
    }

    @action
    setPackageSuccess = (_s: number) => {
        this.packageSuccess = _s;
    }

    @action
    setPackageLost = (_s: number) => {
        this.packageLost = _s;
    }
}